var app = getApp()

Page({
  data: {
    initialHeight: 350,
    height: 350,
    imgUrlList: [],
    urlArr: [],
    tsid: 1,
    smallFilePath: "",
    bigFilePath: "",
    tcontentText: "",
    addFlag: !0,
    data_arr: [],
    switch1Checked:false,
    user_identity:0,
    biaoqiantext:'',
    biaoqianid:0,
    biaoqianpid:0,
    doctor_visible:0,
  },
  switch1Change:function(e){
    console.log(e.detail.value)
    if(e.detail.value){
      this.setData({
        doctor_visible:1
      })
    }else{
      this.setData({
        doctor_visible:0
      })
    }
  },
  goTab:function(){
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/addTab/addTab',
    })
  },
  bindinput: function (t) {
    this.setData({
      tcontentText: t.detail.value
    });
  },
  chooseImage: function (a) {
    var that = this;
    console.log(this.data.imgUrlList)
    if (this.data.imgUrlList.length < 3) {
      wx.chooseImage({
        count: 3,
        sizeType: ['original', 'compressed'],
        success: function (res) {
          console.log(res)
          if (res.tempFilePaths.length == 3) {
            that.setData({
              hide: true
            })
          }
          that.setData({
            imgUrlList: that.data.imgUrlList.concat(res.tempFilePaths)
          })
        }
      })
    } else {
      wx.showToast({
        title: '最多上传三张图片',
        icon: 'loading',
        duration: 3000
      });
    }
  },
  upload: function () {
    var that = this
    var uniacid = that.data.uniacid
    var data_arr = that.data.data_arr;
    for (var i = 0; i < this.data.imgUrlList.length; i++) {
      wx.uploadFile({
        url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Upload&m=hyb_yl',
        filePath: that.data.imgUrlList[i],
        name: 'upfile',
        formData: {},
        success: function (res) {
          data_arr.push(res.data)
          that.setData({
            data_arr: data_arr
          })
        }
      })
    }
  },
  delImage: function (a) {
    var e = this,
      i = this.data.imgUrlList,
      n = a.target.dataset.index;
    // e.default.delImg(e, n, i);
    i.splice(n, 1);
    e.setData({
      imgUrlList: i
    })
  },
  previewImage: function (t) {
    var e = this.data.imgUrlList,
      i = t.target.dataset.imgindex;
    a.previewImage(t, e, i);
  },
  addDynamic: function () {
    var a = this;
    var contents = a.data.tcontentText
    var imgUrlList = this.data.imgUrlList;
    var openid = wx.getStorageSync('openid');
    var biaoqianid = a.data.biaoqianid;
    var user_identity = a.data.user_identity;
    var doctor_visible = a.data.doctor_visible;
    if (0 == (contents || "").replace(/(^\s*)|(\s*$)/g, "").length){
       wx.showToast({
      title: "请输入要发布的内容~",
      icon: "none",
      duration: 2e3
    });
  }else if(imgUrlList.length <= 0){
    wx.showToast({
      title: "请上传动态图片",
      icon: "none",
      duration: 2e3
    });
  }else {
      
      this.upload()
      wx.showLoading({
        title: "发布中请稍后~",
        icon: "loading",
        duration: 2e3,
        mask: !0
      });
      var data_arr = a.data.data_arr;
      
      setTimeout(function () {
        app.util.request({
          url: 'entry/wxapp/share.upbaogaoshare',
          data: {
            openid: openid,
            sharepic: imgUrlList,
            contents: contents,
            state: 1,
            biaoqianid:biaoqianid,
            user_identity:user_identity,
            doctor_visible:doctor_visible,
          },
          success: function (res) {
            
            setTimeout(function () {
              wx.showToast({
                title: "发布成功~",
                icon: "loading",
                duration: 2e3,
                success: function () {
                  wx.navigateBack({
                    delta: 1
                  })
                }
              })
            })
            wx.hideLoading()
          }
        })
      }, 1000)
    }
  },
  onLoad: function (t) {
    var that = this
    var uniacid = app.siteInfo.uniacid;
    var bgc = wx.getStorageSync('color')
    app.util.request({
      'url': 'entry/wxapp/share.url',
      'cachetime': '0',
      success: function (res) {
        console.log(res)
        that.setData({
          url: res.data
        })
      },
    })
    app.util.request({
      'url': 'entry/wxapp/share.user_identity',
      data: {
        openid: wx.getStorageSync('openid')
      },
      success: function (res) {
        that.setData({
          user_identity: res.data
        })
      },
    })
    that.setData({
      uniacid: uniacid,
      bgc: bgc
    })
  }
});